package com.link.base.base.report.controller;

import com.link.base.base.report.model.ConsumerAreaReport;
import com.link.base.base.report.service.ConsumerAreaReportService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 消费者活跃区域分析-
 *
 * @author 谢鑫
 * @date 2019/09/29 09:30
 */
@Controller
@RequestMapping("/link/consumerAreaReport")
public class ConsumerAreaReportController extends BasicController<ConsumerAreaReport> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private ConsumerAreaReportService consumerAreaReportService;

    @Override
    public BasicService<ConsumerAreaReport> getBasicService() throws Exception {
        return consumerAreaReportService;
    }

    /**
     * 查询每个省的总人数和所占百分比
     *
     * @param qps
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping({"/queryBySumExamplePage"})
    @ResponseBody
    public Map<String, Object> queryBySumExamplePage(@JsonParam QueryParams qps, @JsonParam ConsumerAreaReport entity,
                                                     HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
        HashMap result = new HashMap(8);
        try {
            qps.preDealSecurity(request);
            ConsumerAreaReport temp = BasicModel.transformClass(entity, qps);
            List<ConsumerAreaReport> list = consumerAreaReportService.queryBySumExamplePage(entity);
            result.put("success", true);
            result.put("rows", list);
            this.pushCurrentDataCache(list, session.getId(), "base", false);
            result.put("total", getCount(temp, list.size()));
            result.put("code", "200");
        } catch (Exception e) {
            LCLogger.withException(e);
        }
        return result;
    }

    /**
     * 查询指定省的各个城市总人数和所占百分比
     *
     * @param qps
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping({"/queryProvinceByExamplePage"})
    @ResponseBody
    public Map<String, Object> queryProvinceByExamplePage(@JsonParam QueryParams qps, @JsonParam ConsumerAreaReport entity,
                                                     HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
        HashMap result = new HashMap(8);
        try {
            qps.preDealSecurity(request);
            ConsumerAreaReport temp = BasicModel.transformClass(entity, qps);
            List<ConsumerAreaReport> list = consumerAreaReportService.queryProvinceByExamplePage(entity);
            result.put("success", true);
            result.put("rows", list);
            this.pushCurrentDataCache(list, session.getId(), "base", false);
            result.put("total", getCount(temp, list.size()));
            result.put("code", "200");
        } catch (Exception e) {
            LCLogger.withException(e);
        }
        return result;
    }


}
